package dna;




import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;


import core.gui.FileChooser;
import core.inputoutput.formatting.Format;
import core.main.Main;


public class DNAshifterMain extends Main{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		PDBparserDNA parser = new PDBparserDNA();
		DNAshifter conv = new DNAshifter(Format.DNA_ATOMISTIC);
		
		File INPUT =  initializeGUI("PDB Shifter for DNA", parser, conv);
		double[] shifts = parseShift(JOptionPane.showInputDialog("Enter Shift amount - Format: X,Y,Z").trim());
		
		
		
		
		
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(
					makeOutputFileName(INPUT, shifts[0], shifts[1], shifts[2])));
			out.write(conv.applyConverter(parser.parse(INPUT, Format.DNA_ATOMISTIC), 
					shifts[0],
					shifts[1],
					shifts[2]));
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		myGUI.getOPpanel().print("Done!");
		
	}

	private static double[] parseShift(String shift) {
		String[] split = shift.split(",");
		
		return new double[]{Double.parseDouble(split[0].trim()),
							Double.parseDouble(split[1].trim()),
							Double.parseDouble(split[2].trim())};
	}

	private static String makeOutputFileName(File input, double dx, double dy, double dz) {
		if (input.getName().contains("."))
			return input.getName().substring(0,input.getName().indexOf(".")) + "_Shifted("+ dx+ "," + dy +","+ dz +").pdb";
		return input +"shift.pdb";
	}

}
